Given an integer, return an integer that is the reverse ordering of numbers.
reverseInt(15) === 51
reverseInt(981) === 189
reverseInt(500) === 5
reverseInt(-15) === -51
reverseInt(-90) === -9
The input and output should be a number, not a string
Math.sign()
, Number.prototype.toString()
, Global.parseInt()
function reverseInt(n) {
let result = parseInt(n.toString().split("").reverse().join(""));
return result * Math.sign(n);
}
reverseInt(15)
reverseInt(981)
reverseInt(500)
reverseInt(-15)
reverseInt(-90)